/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
 * Description: remote_access_pub.h
 * Author: hanwei
 * Create: 2020-7-21
 */

#ifndef REMOTE_ACCESS_IMPL_H
#define REMOTE_ACCESS_IMPL_H

#include <vector>

#include "remote_access.h"
#include "base.h"
#include "transport_remote_access.h"
#include "comm_remote_access.h"

namespace hccl {
class RemoteAccessImpl {
public:
    explicit RemoteAccessImpl();
    virtual ~RemoteAccessImpl();
    HcclResult Init(u32 rank, const std::vector<MemRegisterAddr>& addrInfos, const RmaRankTable &rankTable);
    HcclResult RemoteRead(const std::vector<HcomRemoteAccessAddrInfo>& addrInfos, HcclRtStream stream);
    HcclResult RemoteWrite(const std::vector<HcomRemoteAccessAddrInfo>& addrInfos, HcclRtStream stream);
private:
    void ParseRemoteAccessAddrInfo(const std::vector<HcomRemoteAccessAddrInfo>& addrInfos,
                                   std::map<u32, std::vector<HcomRemoteAccessAddrInfo>>& addrInfoMap);
    HcclResult IsInSamePlane(const u32 userRank, const std::vector<HcomRemoteAccessAddrInfo>& addrInfos);
    std::unique_ptr<CommRemoteAccess> comm_;
    u32 userRank_;
    u32 userRankNum_;
    u32 serverNum_;
    u32 rankNumPerServer_;  // 默认约束：每个server的rank数必须相同
};
}

#endif  // REMOTE_ACCESS_IMPL_H